/**
 * Project: greenline-rms-schedule-biz-core
 * 
 * File Created at 2013年12月23日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package com.greenline.pay.schedule.biz.task.controller;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.greenline.pay.schedule.biz.task.pay.impl.PayOvertimeTaskImpl;

/**
 * @Type PayOvertimeTaskController
 * @Desc 支付超时处理任务
 * @author jisc
 * @date 2013年12月23日
 * @Version V1.0
 */
@Controller
@RequestMapping("/schedule/pay")
public class PayOvertimeTaskController {

	private Log log = LogFactory.getLog(this.getClass());
			
	@Resource
	private PayOvertimeTaskImpl payOvertimeTaskImpl;
	
	@RequestMapping(value = "/overtime")
	public String updateWhenPayTimeTask(ModelMap model) {
		log.info("------支付超时处理任务开始------");
		
		MyThread thread = new MyThread();
		thread.start();
		
		log.info("------支付超时处理任务结束------");
		model.put("title", "支付超时处理任务");
		model.put("message", "支付超时处理任务启动成功");
		return "/result.jsp";
	}
	
	private class MyThread extends Thread{
		
		public void run() {
			try {
				payOvertimeTaskImpl.execute();
			} catch (Exception e) {
				e.printStackTrace();
				log.info(e);
				log.info("支付超时处理任务运行失败");
				return;
			}
			log.info("支付超时处理任务运行成功");
		}
	}
	
}
